﻿/// <reference path="../scripts/controllers.js" />
/// <reference path="../scripts/libs/qunit.js" />
/// <reference path="../scripts/gameObject.js" />
/// <reference path="../scripts/gameObjectFactory.js" />
/// <reference path="../scripts/highScoreDialog.js" />
/// <reference path="../scripts/nextFigure.js" />
/// <reference path="../scripts/prototypeExtensions.js" />
/// <reference path="../scripts/scoreBoard.js" />
/// <reference path="../scripts/settings.js" />
/// <reference path="../scripts/twitterButton.js" />

module("Game objects namespace");
test("Game objects namespace exists", function () {
    ok(typeof (gameObjects) !== "undefined", "The gameObjects namespace exists");
});

test("Game object exists", function () {
    ok(typeof (gameObjects.GameObject) !== "undefined", "The GameObject object exists");
});

test("Game object has a constructor", function () {
    ok(typeof (gameObjects.GameObject.init) !== "undefined", "The GameObject has a constructor");
});

test("Game field exists", function () {
    ok(typeof (gameObjects.GameField) !== "undefined", "The GameField object exists");
});

test("Game field has a constructor", function () {
    ok(typeof (gameObjects.GameField.init) !== "undefined", "The GameField has a constructor");
});

test("Game field inherits from GameObject", function () {
    var field = gameObjects.GameField.init("#fixture");
    equal(field._super, gameObjects.GameObject, "The GameField is a GameObject");
});

test("Game field creates a proper array", 2, function () {
    var field = gameObjects.GameField.init("#fixture");
    equal(field._fieldArray.length, FieldRows, "The GameField creates a proper array rows");
    equal(field._fieldArray[0].length, FieldCols, "The GameField creates a proper array columns");
});

test("Figure exists", function () {
    ok(typeof (gameObjects.Figure) !== "undefined", "The Figure object exists");
});

test("Figure has a constructor", function () {
    ok(typeof (gameObjects.Figure.init) !== "undefined", "The Figure has a constructor");
});

test("Figure inherits from GameObject", function () {
    var figure = gameObjects.Figure.init();
    equal(figure._super, gameObjects.GameObject, "The Figure is a GameObject");
});

test("Figure has all required properties", 5, function () {
    var figure = gameObjects.Figure.init("figureId", "#000000", 0);
    equal(figure._id, "figureId", "Proper figure ID");
    equal(figure.color, "#000000", "Proper figure colour");
    equal(figure._currentRotation, 0, "Proper figure rotation");
    equal(figure._x, 60, "Proper figure initial coordinates - x");
    equal(figure._y, -20, "Proper figure initial coordinates - y");
});

test("Figure has a method to initialize body", function () {
    ok(typeof (gameObjects.Figure.initCoords) !== "undefined", "The Figure has an initCoords() method");
});

test("Dash exists", function () {
    ok(typeof (gameObjects.Dash) !== "undefined", "The Dash object exists");
});

test("Dash has a constructor", function () {
    ok(typeof (gameObjects.Dash.init) !== "undefined", "The Dash has a constructor");
});

test("Dash inherits from Figure", function () {
    var dash = gameObjects.Dash.init();
    equal(dash._super, gameObjects.Figure, "The Dash is a Figure");
});

test("Dash has all required properties", 2, function () {
    var dash = gameObjects.Dash.init(0);
    equal(dash._id, "dash", "Proper figure ID");
    equal(dash._currentRotation, 0, "Proper figure rotation");
});

test("Dash has all required properties - set while creating", 2, function () {
    var dash = gameObjects.Dash.init(2);
    equal(dash._id, "dash", "Proper figure ID");
    equal(dash._currentRotation, 2, "Proper figure rotation");
});

test("Dash has a method to initialize body", function () {
    ok(typeof (gameObjects.Dash.initCoords) !== "undefined", "The Dash has an initCoords() method");
});

test("Dash has a method to add keyboard event handlers", function () {
    ok(typeof (gameObjects.Dash._addHandlers) !== "undefined", "The Dash has an addHandlers() method");
});

test("TElement exists", function () {
    ok(typeof (gameObjects.TElement) !== "undefined", "The TElement object exists");
});

test("TElement has a constructor", function () {
    ok(typeof (gameObjects.TElement.init) !== "undefined", "The TElement has a constructor");
});

test("TElement inherits from Figure", function () {
    var tElement = gameObjects.TElement.init();
    equal(tElement._super, gameObjects.Figure, "The TElement is a Figure");
});

test("TElement has all required properties", 2, function () {
    var tElement = gameObjects.TElement.init(0);
    equal(tElement._id, "tElement", "Proper figure ID");
    equal(tElement._currentRotation, 0, "Proper figure rotation");
});

test("TElement has all required properties - set while creating", 2, function () {
    var tElement = gameObjects.TElement.init(2);
    equal(tElement._id, "tElement", "Proper figure ID");
    equal(tElement._currentRotation, 2, "Proper figure rotation");
});

test("TElement has a method to initialize body", function () {
    ok(typeof (gameObjects.TElement.initCoords) !== "undefined", "The TElement has an initCoords() method");
});

test("TElement has a method to add keyboard event handlers", function () {
    ok(typeof (gameObjects.TElement._addHandlers) !== "undefined", "The TElement has an addHandlers() method");
});

test("LElement exists", function () {
    ok(typeof (gameObjects.LElement) !== "undefined", "The LElement object exists");
});

test("LElement has a constructor", function () {
    ok(typeof (gameObjects.LElement.init) !== "undefined", "The LElement has a constructor");
});

test("LElement inherits from Figure", function () {
    var lElement = gameObjects.LElement.init();
    equal(lElement._super, gameObjects.Figure, "The LElement is a Figure");
});

test("LElement has all required properties", 2, function () {
    var lElement = gameObjects.LElement.init(0);
    equal(lElement._id, "lElement", "Proper figure ID");
    equal(lElement._currentRotation, 0, "Proper figure rotation");
});

test("LElement has all required properties - set while creating", 2, function () {
    var lElement = gameObjects.LElement.init(2);
    equal(lElement._id, "lElement", "Proper figure ID");
    equal(lElement._currentRotation, 2, "Proper figure rotation");
});

test("LElement has a method to initialize body", function () {
    ok(typeof (gameObjects.LElement.initCoords) !== "undefined", "The LElement has an initCoords() method");
});

test("LElement has a method to add keyboard event handlers", function () {
    ok(typeof (gameObjects.LElement._addHandlers) !== "undefined", "The LElement has an addHandlers() method");
});

test("JElement exists", function () {
    ok(typeof (gameObjects.JElement) !== "undefined", "The JElement object exists");
});

test("JElement has a constructor", function () {
    ok(typeof (gameObjects.JElement.init) !== "undefined", "The JElement has a constructor");
});

test("JElement inherits from Figure", function () {
    var jElement = gameObjects.JElement.init();
    equal(jElement._super, gameObjects.Figure, "The JElement is a Figure");
});

test("JElement has all required properties", 2, function () {
    var jElement = gameObjects.JElement.init(0);
    equal(jElement._id, "jElement", "Proper figure ID");
    equal(jElement._currentRotation, 0, "Proper figure rotation");
});

test("JElement has all required properties - set while creating", 2, function () {
    var jElement = gameObjects.JElement.init(2);
    equal(jElement._id, "jElement", "Proper figure ID");
    equal(jElement._currentRotation, 2, "Proper figure rotation");
});

test("JElement has a method to initialize body", function () {
    ok(typeof (gameObjects.JElement.initCoords) !== "undefined", "The JElement has an initCoords() method");
});

test("JElement has a method to add keyboard event handlers", function () {
    ok(typeof (gameObjects.JElement._addHandlers) !== "undefined", "The JElement has an addHandlers() method");
});

test("ZElement exists", function () {
    ok(typeof (gameObjects.ZElement) !== "undefined", "The ZElement object exists");
});

test("ZElement has a constructor", function () {
    ok(typeof (gameObjects.ZElement.init) !== "undefined", "The ZElement has a constructor");
});

test("ZElement inherits from Figure", function () {
    var zElement = gameObjects.ZElement.init();
    equal(zElement._super, gameObjects.Figure, "The ZElement is a Figure");
});

test("ZElement has all required properties", 2, function () {
    var zElement = gameObjects.ZElement.init(0);
    equal(zElement._id, "zElement", "Proper figure ID");
    equal(zElement._currentRotation, 0, "Proper figure rotation");
});

test("ZElement has all required properties - set while creating", 2, function () {
    var zElement = gameObjects.ZElement.init(2);
    equal(zElement._id, "zElement", "Proper figure ID");
    equal(zElement._currentRotation, 2, "Proper figure rotation");
});

test("ZElement has a method to initialize body", function () {
    ok(typeof (gameObjects.ZElement.initCoords) !== "undefined", "The ZElement has an initCoords() method");
});

test("ZElement has a method to add keyboard event handlers", function () {
    ok(typeof (gameObjects.ZElement._addHandlers) !== "undefined", "The ZElement has an addHandlers() method");
});

test("SElement exists", function () {
    ok(typeof (gameObjects.SElement) !== "undefined", "The SElement object exists");
});

test("SElement has a constructor", function () {
    ok(typeof (gameObjects.SElement.init) !== "undefined", "The SElement has a constructor");
});

test("SElement inherits from Figure", function () {
    var sElement = gameObjects.SElement.init();
    equal(sElement._super, gameObjects.Figure, "The SElement is a Figure");
});

test("SElement has all required properties", 2, function () {
    var sElement = gameObjects.SElement.init(0);
    equal(sElement._id, "sElement", "Proper figure ID");
    equal(sElement._currentRotation, 0, "Proper figure rotation");
});

test("SElement has all required properties - set while creating", 2, function () {
    var sElement = gameObjects.SElement.init(2);
    equal(sElement._id, "sElement", "Proper figure ID");
    equal(sElement._currentRotation, 2, "Proper figure rotation");
});

test("SElement has a method to initialize body", function () {
    ok(typeof (gameObjects.SElement.initCoords) !== "undefined", "The SElement has an initCoords() method");
});

test("SElement has a method to add keyboard event handlers", function () {
    ok(typeof (gameObjects.SElement._addHandlers) !== "undefined", "The SElement has an addHandlers() method");
});

test("Square exists", function () {
    ok(typeof (gameObjects.Square) !== "undefined", "The Square object exists");
});

test("Square has a constructor", function () {
    ok(typeof (gameObjects.Square.init) !== "undefined", "The Square has a constructor");
});

test("Square inherits from Figure", function () {
    var square = gameObjects.Square.init();
    equal(square._super, gameObjects.Figure, "The Square is a Figure");
});

test("Square has all required properties", 2, function () {
    var square = gameObjects.Square.init(0);
    equal(square._id, "square", "Proper figure ID");
    equal(square._currentRotation, 0, "Proper figure rotation");
});

test("Square has all required properties - set while creating", 2, function () {
    var square = gameObjects.Square.init(2);
    equal(square._id, "square", "Proper figure ID");
    equal(square._currentRotation, 2, "Proper figure rotation");
});

test("Square has a method to initialize body", function () {
    ok(typeof (gameObjects.Square.initCoords) !== "undefined", "The Square has an initCoords() method");
});

test("Square has a method to add keyboard event handlers", function () {
    ok(typeof (gameObjects.Square._addHandlers) !== "undefined", "The Square has an addHandlers() method");
});

module("Game object factory namespace");
test("Game object factory namespace exists", function () {
    ok(typeof (gameObjectFactory) !== "undefined", "The gameObjectFactory namespace exists");
});

test("The factory has a method to get a figure by ID", function () {
    ok(typeof (gameObjectFactory.getFigure) !== "undefined", "The factory has a method to get a figure by ID");
});

test("The factory has a method to get random figure", function () {
    ok(typeof (gameObjectFactory.getRandomFigure) !== "undefined", "The factory has a method to get a random figure");
});

test("The method to get a figure by ID works for Dash", function () {
    var dash = gameObjectFactory.getFigure("dash");
    equal(dash._super, gameObjects.Figure, "The object is a figure");
    equal(dash._id, "dash", "The object is a a proper type");
    equal(dash._currentRotation, 0, "The object has a proper rotation");
});

test("The method to get a figure by ID works for Dash - specified rotation", function () {
    var dash = gameObjectFactory.getFigure("dash", 2);
    equal(dash._super, gameObjects.Figure, "The object is a figure");
    equal(dash._id, "dash", "The object is a a proper type");
    equal(dash._currentRotation, 2, "The object has a proper rotation");
});

test("The method to get a figure by ID works for Dash - has keyboard event handlers", function () {
    var dash = gameObjectFactory.getFigure("dash");
    ok(dash._addHandlers !== undefined, "The Dash has a method to attach keyboard event handlers");
});

test("The method to get a figure by ID works for TElement", function () {
    var tElement = gameObjectFactory.getFigure("tElement");
    equal(tElement._super, gameObjects.Figure, "The object is a figure");
    equal(tElement._id, "tElement", "The object is a a proper type");
    equal(tElement._currentRotation, 0, "The object has a proper rotation");
});

test("The method to get a figure by ID works for TElement - specified rotation", function () {
    var tElement = gameObjectFactory.getFigure("tElement", 2);
    equal(tElement._super, gameObjects.Figure, "The object is a figure");
    equal(tElement._id, "tElement", "The object is a a proper type");
    equal(tElement._currentRotation, 2, "The object has a proper rotation");
});

test("The method to get a figure by ID works for TElement - has keyboard event handlers", function () {
    var tElement = gameObjectFactory.getFigure("tElement");
    ok(tElement._addHandlers !== undefined, "The TElement has a method to attach keyboard event handlers");
});

test("The method to get a figure by ID works for LElement", function () {
    var lElement = gameObjectFactory.getFigure("lElement");
    equal(lElement._super, gameObjects.Figure, "The object is a figure");
    equal(lElement._id, "lElement", "The object is a a proper type");
    equal(lElement._currentRotation, 0, "The object has a proper rotation");
});

test("The method to get a figure by ID works for LElement - specified rotation", function () {
    var lElement = gameObjectFactory.getFigure("lElement", 2);
    equal(lElement._super, gameObjects.Figure, "The object is a figure");
    equal(lElement._id, "lElement", "The object is a a proper type");
    equal(lElement._currentRotation, 2, "The object has a proper rotation");
});

test("The method to get a figure by ID works for LElement - has keyboard event handlers", function () {
    var lElement = gameObjectFactory.getFigure("lElement");
    ok(lElement._addHandlers !== undefined, "The LElement has a method to attach keyboard event handlers");
});

test("The method to get a figure by ID works for JElement", function () {
    var jElement = gameObjectFactory.getFigure("jElement");
    equal(jElement._super, gameObjects.Figure, "The object is a figure");
    equal(jElement._id, "jElement", "The object is a a proper type");
    equal(jElement._currentRotation, 0, "The object has a proper rotation");
});

test("The method to get a figure by ID works for JElement - specified rotation", function () {
    var jElement = gameObjectFactory.getFigure("jElement", 2);
    equal(jElement._super, gameObjects.Figure, "The object is a figure");
    equal(jElement._id, "jElement", "The object is a a proper type");
    equal(jElement._currentRotation, 2, "The object has a proper rotation");
});

test("The method to get a figure by ID works for JElement - has keyboard event handlers", function () {
    var jElement = gameObjectFactory.getFigure("jElement");
    ok(jElement._addHandlers !== undefined, "The JElement has a method to attach keyboard event handlers");
});

test("The method to get a figure by ID works for ZElement", function () {
    var zElement = gameObjectFactory.getFigure("zElement");
    equal(zElement._super, gameObjects.Figure, "The object is a figure");
    equal(zElement._id, "zElement", "The object is a a proper type");
    equal(zElement._currentRotation, 0, "The object has a proper rotation");
});

test("The method to get a figure by ID works for ZElement - specified rotation", function () {
    var zElement = gameObjectFactory.getFigure("zElement", 2);
    equal(zElement._super, gameObjects.Figure, "The object is a figure");
    equal(zElement._id, "zElement", "The object is a a proper type");
    equal(zElement._currentRotation, 2, "The object has a proper rotation");
});

test("The method to get a figure by ID works for ZElement - has keyboard event handlers", function () {
    var zElement = gameObjectFactory.getFigure("zElement");
    ok(zElement._addHandlers !== undefined, "The ZElement has a method to attach keyboard event handlers");
});

test("The method to get a figure by ID works for SElement", function () {
    var sElement = gameObjectFactory.getFigure("sElement");
    equal(sElement._super, gameObjects.Figure, "The object is a figure");
    equal(sElement._id, "sElement", "The object is a a proper type");
    equal(sElement._currentRotation, 0, "The object has a proper rotation");
});

test("The method to get a figure by ID works for SElement - specified rotation", function () {
    var sElement = gameObjectFactory.getFigure("sElement", 2);
    equal(sElement._super, gameObjects.Figure, "The object is a figure");
    equal(sElement._id, "sElement", "The object is a a proper type");
    equal(sElement._currentRotation, 2, "The object has a proper rotation");
});

test("The method to get a figure by ID works for SElement - has keyboard event handlers", function () {
    var sElement = gameObjectFactory.getFigure("sElement");
    ok(sElement._addHandlers !== undefined, "The SElement has a method to attach keyboard event handlers");
});

test("The method to get a figure by ID works for Square", function () {
    var square = gameObjectFactory.getFigure("square");
    equal(square._super, gameObjects.Figure, "The object is a figure");
    equal(square._id, "square", "The object is a a proper type");
    equal(square._currentRotation, 0, "The object has a proper rotation");
});

test("The method to get a figure by ID works for Square - specified rotation", function () {
    var square = gameObjectFactory.getFigure("square", 2);
    equal(square._super, gameObjects.Figure, "The object is a figure");
    equal(square._id, "square", "The object is a a proper type");
    equal(square._currentRotation, 2, "The object has a proper rotation");
});

test("The method to get a figure by ID works for Square - has keyboard event handlers", function () {
    var square = gameObjectFactory.getFigure("square");
    ok(square._addHandlers !== undefined, "The Square has a method to attach keyboard event handlers");
});

